import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamDemo {
    
    public static void main(String[] args) {
        List<Task> taskList = new ArrayList<Task>();
        Task t1 = new Task(1,"t1");
        Task t2 = new Task(2,"t2");
        Task t3 = new Task(3,"t3");
        Task t4 = new Task(4,"t4");
        Task t5 = new Task(1,"t5");
    
        taskList.add(t1);
        taskList.add(t2);
        taskList.add(t3);
        taskList.add(t4);
        taskList.add(t5);
    
        //list转map<key,v> 如果有重复 则取第一个key
        taskList.stream().collect(Collectors.toMap(Task::getType,(v)->v.getValue(),(k1,k2)->k1));
        //list转map<key,list> 进行分组
        taskList.stream().collect(Collectors.groupingBy((e)->e.getType()));
        //过滤
        taskList.stream().filter(e->e.getType()==1).collect(Collectors.toList());
        //求和
        taskList.stream().map(Task::getType).reduce(0,Integer::sum);
    }
}
